﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using DevExpress.Web.ASPxGridView;
using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;

public partial class UFTList : ICPRelationshipPage
{
    public bool bClose;
    public bool bSubmitted;
    #region Properties
    #endregion Properties

    #region Event Handlers
    protected override void Page_Load(object sender, EventArgs e)
    {
        m_lsPermittedRoles.Add(ICPUserRole.CAR);
        base.Page_Load(sender, e);
        Page.Title = "ICP Lintasarta: Relationship, List of Events";

        bSubmitted = Context.ReadQuery("mode").ToUpper() == "SUBMITTED";
            
        InitEventList();
    }
    
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    
    private void InitEventList()
    {
        DataTable dtEventList = DBQuery.EventTable.GetEventList(bSubmitted, ICPUser.IsAdmin, ICPUser.IsAdminForum);

        dgEventList.DataSource = dtEventList;
        dgEventList.DataBind();
		dgEventList.Columns["EMAIL"].Visible = bSubmitted;
        dgEventList.Columns["INVITE"].Visible = bSubmitted;
        dgEventList.Columns["CLOSE"].Visible = bSubmitted;
        dgEventList.Columns["CONFIRM"].Visible = bSubmitted;
    }
	public String GetSetEmailColumnContent(String id, String sxNew)
    {
        String sxOutput = String.Empty;

        bool bAdmin = ICPUser.IsAdmin;
        bool bAdminForum = ICPUser.IsAdminForum;

        if (bSubmitted)
        {
            if ((bAdmin || bAdminForum) && sxNew == "Y")
            {
                sxOutput = String.Format("<a href=\"UFTSetEmail.aspx?eid={0}\">Set Email</a>", id);
            }
            else
            {
                sxOutput = "-";
            }
        }

        return sxOutput;
    }
    public String GetInviteColumnContent(String id, String sxNew)
    {
        String sxOutput = String.Empty;

        if (bSubmitted)
        {
            if (sxNew == "Y")
            {
                sxOutput = String.Format("<a href=\"UFTGuest.aspx?eid={0}\">Invite</a>", id);
            }
            else
            {
                sxOutput = "-";
            }
        }

        return sxOutput;
    }

    public String GetConfirmColumnContent(String id, String sxInvite, String sxClose, String sxConfirm)
    {
        String sxOutput = String.Empty;

        if (bSubmitted)
        {
            if (sxInvite == "Y" && sxConfirm == "N" && sxClose == "N")
            {
                sxOutput = String.Format("<a href=\"UFTConfirm.aspx?eid={0}\">Confirm</a>", id);
            }
            else if (sxInvite == "Y" && sxConfirm == "Y" && sxClose == "N")
            {
                sxOutput = "-";
            }
            else if (sxInvite == "N" && sxConfirm == "N" && sxClose == "N")
            {
                sxOutput = "-";
            }
            else if (sxClose == "Y")
            {
                sxOutput = "-";
            }
            else
            {
                sxOutput = "-";
            }
        }

        return sxOutput;
    }

    public String GetCloseColumnContent(String id, String sxInvite, String sxClose, String sxConfirm)
    {
        String sxOutput = String.Empty;

        bool bAdmin = ICPUser.IsAdmin;
		bool bAdminForum = ICPUser.IsAdminForum;
		
        if (bSubmitted)
        {
            if ((bAdmin || bAdminForum) && sxClose == "N" && sxConfirm == "Y" && sxInvite == "Y")
            {
                sxOutput = String.Format("<a href=\"UFTClose.aspx?eid={0}\">Close</a>", id);
            }
            else if ((bAdmin || bAdminForum) && sxClose == "Y")
            {
                sxOutput = "Closed";
            }
            else
            {
                sxOutput = "-";
            }
        }

        return sxOutput;
    }
    #endregion Custom Methods
}
